package com.lin.mr.maizilaundry.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.lin.mr.maizilaundry.R;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends Activity {
    private Button btn_welcome;
    private boolean flag = true;
    private RelativeLayout rl_welcome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        btn_welcome = (Button) findViewById(R.id.btn_welcome);
        rl_welcome = (RelativeLayout) findViewById(R.id.rl_welcome);
        btn_welcome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flag = false;
                //下面这种写法的目的是为了初始化HomeActivity
                Intent intent1 = new Intent(WelcomeActivity.this, HomeActivity.class);
                Intent intent2 = new Intent(WelcomeActivity.this, ClothActivity.class);
                startActivities(new Intent[]{intent1,intent2});
                finish();
            }
        });

        //渐变动画
        AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
        alphaAnimation.setDuration(1500);
        rl_welcome.setAnimation(alphaAnimation);
        alphaAnimation.start();
        alphaAnimation.setFillAfter(true);

        Timer timer = new Timer();
        timer.schedule(new Task(),1500);
    }

   class Task extends TimerTask {
        @Override
        public void run() {
            if (flag){
//                boolean isFirst = ShareUtils.getFirstTime(WelcomeActivity.this);
//            if (isFirst){ //判断用户是否是第一次启动App
//                Intent intent = new Intent(WelcomeActivity.this,LoginActivity2.class);
//                startActivity(intent);
//                finish();
//            }else {
//                startActivity(new Intent(WelcomeActivity.this,GuideActivity.class));
//                finish();
//            }
                startActivity(new Intent(WelcomeActivity.this,GuideActivity.class));
                finish();
            }
        }
    }
}
